<?php
/**
 * @package Content - Related News
 * @version 1.7.0
 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 * @copyright (c) 2012 YouTech Company. All Rights Reserved.
 * @author YouTech Company http://www.smartaddons.com
 *
 */
defined('_JEXEC') or die;

if ((int)$this->params->get('item_image_display', 1)){
	$image_config = array(
		'output_width'  => $this->params->get('item_image_width', 16),
		'output_height' => $this->params->get('item_image_height',16),
		'function'		=> $this->params->get('item_image_function', 'stretch'),
		'background'	=> $this->params->get('item_image_background', '#FFFFFF')
	);
	$image_resized = array();
	foreach ($items as $id => $item){
		$image_resized[$item->id] = SjTools::resize($item->image, $image_config);
	}
}
if (count($items)){
	if ((int)$this->params->get('usecss', 1)){
		$css_url = JURI::root() . 'plugins/content/relatednews/assets/css/relatednews.css';
		$document = &JFactory::getDocument();
		$document->addStyleSheet($css_url);
	}
	if ($this->params->get('title')){
		echo '<div class="related-items-title">';
		echo $this->params->get('title');
		echo '</div>';
	}
	echo '<ul class="related-items">';
	foreach ($items as $id => $item) { ?>
		<li class="related-item">
		<?php
		if ((int)$this->params->get('item_image_display', 1)): ?>
			<a class="related-item-image-link" href="<?php echo $item->url; ?>"
				<?php echo SjTools::parseTarget($this->params->get('item_link_target')); ?>
			>
				<img
					src="<?php echo $image_resized[$item->id]; ?>"
					alt="<?php echo $item->title; ?>"
					title="<?php echo $item->title; ?>"
				/>
			</a>
		<?php
		endif; // image display ?>
		<?php
		if ((int)$this->params->get('item_date_display', 1)==1): ?>
			<a href="<?php echo $item->url; ?>"
				<?php echo SjTools::parseTarget($this->params->get('item_link_target')); ?>
			><span class="related-item-date"><?php echo JHtml::date($item->created, 'Y-m-d - h:i:s'); ?></span> - </a>
		<?php
		endif;
		?>
			<a href="<?php echo $item->url; ?>"
				<?php echo SjTools::parseTarget($this->params->get('item_link_target')); ?>
			><?php echo SjTools::truncate($item->title, $this->params->get('item_title_max_characters')); ?></a>
		<?php
		if ((int)$this->params->get('item_date_display', 1)==2): ?>
			<a href="<?php echo $item->url; ?>"
				<?php echo SjTools::parseTarget($this->params->get('item_link_target')); ?>
			> - <span class="related-item-date"><?php echo JHtml::date($item->created, 'Y-m-d - h:i:s'); ?></span></a>
		<?php
		endif;
		?>
		</li>
	<?php
	}
	echo '</ul>';
}